package com.example.administrator.managesystem.adapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.administrator.managesystem.R;
import com.example.administrator.managesystem.bean.GetCameraBean;
import com.example.administrator.managesystem.bean.LandListBean;

public class GridViewAdapter extends BaseAdapter {
    private List<String> series_list=new ArrayList<>();
    private Context mContext;
    private boolean isShowDelete;// 根据这个变量来判断是否显示删除图标，true是显示，false是不显示

    public GridViewAdapter(Context mContext) {
        this.mContext = mContext;
        // this.names=names;
    }
   public void addDatas(List<GetCameraBean.DataBean> myList){
        series_list.clear();
        for(int i=0;i<myList.size();i++){
            series_list.add(myList.get(i).getDevice_number());
        }

   }
    public void setIsShowDelete(boolean isShowDelete) {
        this.isShowDelete = isShowDelete;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return series_list.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return series_list.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }


    @SuppressLint("ResourceType")
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {


       ViewHolder viewHolder;
        if(convertView==null) {
            convertView=View.inflate(mContext, R.layout.camera_grid_item, null);
            viewHolder=new ViewHolder();
            viewHolder.camera_name=convertView.findViewById(R.id.camera_name);
            viewHolder.deleteView = convertView.findViewById(R.id.delete_markView);

            convertView.setTag(viewHolder);//store up viewHolder
        }else {

            viewHolder=(ViewHolder)convertView.getTag();
        }


        viewHolder.deleteView.setVisibility(isShowDelete ? View.VISIBLE : View.GONE);// 设置删除按钮是否显示
        viewHolder.camera_name.setText( series_list.get(position));

        return convertView;
    }

    private class ViewHolder{
        TextView camera_name;
        ImageView deleteView;

    }

}